package com.uuah.server.exception.transport;

import com.uuah.config.i18n.Message;
import com.uuah.server.api.transport.IConnector;
import com.uuah.server.config.i18n.ServerMessages;
import com.uuah.server.exception.AbstractUuahServerException;

/**
 * <code>ConnectorException</code> Is thrown in the context of a Connector,
 * usually some sort of transport level error where the connection has failed.
 * This exception maintains a reference to the connector.
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:43:59
 * @version 1.0.0
 */
public class ConnectorException extends AbstractUuahServerException {
	private static final long serialVersionUID = 4729481487016346035L;

	private transient IConnector connector;

	public ConnectorException(Message message, IConnector connector) {
		super(generateMessage(message, connector));
		this.connector = connector;
	}

	public ConnectorException(Message message, IConnector connector,
			Throwable cause) {
		super(generateMessage(message, connector), cause);
		this.connector = connector;
	}

	private static Message generateMessage(Message message, IConnector connector) {
		Message m = ServerMessages.connectorCausedError(connector);
		if (message != null) {
			message.setNextMessage(m);
		}
		return message;
	}

	public IConnector getConnector() {
		return connector;
	}
}
